How to solve these coding challenges:
Write your solution in PyCharm or in your preferred Python IDE.
If your solution is not correct, then try to understand the error messages, watch the video again, rewrite the solution, and test it again. Repeat this step until you get the correct solution.
Save the solution in a file for future reference or recap.
Challenge #1
Create a Python script that uses openpyxl and generates an Excel file with a single sheet and the below content:
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #2
Change the solution from the previous challenge and set the sheet title to COMPANY SALES.
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #3
Consider this Excel file.
a) Add a new sheet called VAT.
b) Read the Excel file in Python, calculate the VAT if the VAT rate is 15%, and write the data into the new sheet.
c) Save the Excel file as a new file called sales_and_vat.xlsx
It should look like this one.
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #4
Consider this Excel file.
Add an Excel formula into the B6 cell so that it calculates the total sales.
Add the string Total Sales into cell C6.
The sheet should look like this:
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #5
Consider the Excel file generated in the previous challenge.
Format the cells B6 and C6 in the following way: Tahoma font family, size 16, color red, and bold.
The sheet should look like this:
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #6
Create a Python script that contains a function called csv2excel() which exports any CSV file to an excel one.
The function will be called like this: csv2excel('people3.csv', 'teachers.xlsx')
It will read the CSV file called people3.csv and export it to teacher.xlsx
Sample files: people3.csv and teacher.xlsx
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #7
Change the solution of the previous challenge so that the CSV file can use any delimiter (not only comma).
Are you stuck? Do you want to see the solution to this exercise? Click here.
Challenge #8
Create a Python script that contains a function called excel2csv() which exports any Excel file to CSV one.
The function will be called like this: excel2csv('books.xlsx', 'booklist.csv')
It will read the Excel file called books.xlsx and export it to booklist.csv
Sample files: books.xls and booklist.csv
Are you stuck? Do you want to see the solution to this exercise? Click here.